import { createRouter, createWebHashHistory } from "vue-router";
const routes = [
  {
    name: "start", //路由名称
    path: "/start", //路由匹配的路径,"/"表示根路径
    component: () => import("../view/start/start.vue"),
    beforeEnter: (to, from, next) => {
     console.log(from);
      console.log(to);
      next()
    }
  },
  {
    name: "home", //路由名称
    path: "/", //路由匹配的路径,"/"表示根路径
    redirect: "/start",
  },
  {
    name: "main", //路由名称
    path: "/main", //路由匹配的路径,"/"表示根路径
    component: () => import("../components/main.vue"), //匹配Home组件,注意需要导入
    meta: { title: "首页" }, //定义元数据,将来用得上,比如对应的标题
  },
  {
    name: "Login",
    path: "/login",
    component: () => import("../view/login.vue"),
    meta: { title: "登录页" },
  },
  {
    name: "register",
    path: "/register",
    component: () => import("../view/register.vue"),
    meta: { title: "注册页" },
  },
  {
    name: "reset",
    path: "/reset",
    component: () => import("../view/reset.vue"),
    meta: { title: "重置密码页" },
  },
  {
    name: "search",
    path: "/search",
    component: () => import("../view/searchVue.vue"),
    meta: { title: "搜索页" },
  },
  {
    name: "cooperate",
    path: "/cooperate",
    component: () => import("../components/cooperate/cooperate.vue"),
    meta: { title: "医疗协作" },
  },
  {
    name: "buy",
    path: "/buy",
    component: () => import("../components/cooperate/cooList/buy/buy.vue"),
    meta: { title: "药品采购界面" },
  },
  {
    name: "shop",
    path: "/shop/:id",
    component: () => import("../components/cooperate/cooList/buy/shop.vue"),
    meta: { title: "药品界面" },
  },
  {
    name: "orders",
    path: "/orders",
    component: () => import("../components/cooperate/cooList/buy/orders.vue"),
    meta: { title: "药品订单界面" },
  },
  {
    name: "business",
    path: "/business",
    component: () => import("../components/cooperate/cooList/buy/business.vue"),
    meta: { title: "商家界面" },
  },
  {
    name: "mailList",
    path: "/mailList",
    component: () => import("../components/mailList/mailList.vue"),
    redirect: "/mailList/office/message",
    meta: { title: "通讯录" },
    children: [
      {
        name: "office",
        path: "office",
        component: () => import("../components/mailList/office/office.vue"),
        children: [
          {
            name: "message",
            path: "message",
            component: () =>
              import("../components/mailList/message/contacts.vue"),
          },
          {
            name: "groupChat",
            path: "groupChat",
            component: () =>
              import("../components/mailList/Group chat/groupChat.vue"),
          },
        ],
      },
      {
        name: "patient",
        path: "patient",
        component: () => import("../components/mailList/patient/patient.vue"),
      },
    ],
  },
  {
    name: "chat",
    path: "/mailList/chat/:name",
    component: () => import("../components/chat/chat.vue"),
  },
  {
    name: "groupchat",
    path: "/mailList/groupchat",
    component: () => import("../components/chat/groupChat.vue"),
    meta: { title: "群聊" },
  },
  {
    name: "mine",
    path: "/mine",
    component: () => import("../components/mine/mine.vue"),
    meta: { title: "我的" },
  },
  {
    name: "setting",
    path: "/mine/setting",
    component: () => import("../view/setting.vue"),
    meta: { title: "设置" },
  },
  {
    name: "authentication",
    path: "/authentication",
    component: () => import("../view/authentication.vue"),
    meta: { title: "设置" },
  },
  {
    name: "error",
    path: "/:catchAll(.*)",
    component: () => import("../view/error/index.vue"),
    meta: { title: "错误" },
  },
];

export default createRouter({
  history: createWebHashHistory(),
  routes: routes,
});
